<template>
  <div class="home-classic">
    <h1>经典歌单</h1>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li v-for="(item, index) in listData" :key="index" @click="selectItem(item)">
          <div class="cover">
            <van-image :src="item.cover_url_medium" radius="10" />
            <span>{{ item.access_num | numFilter(1) }}万</span>
          </div>
          <span>{{ item.title }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { betterScrollHorizontal } from "../../common/betterScroll";
export default {
  data() {
    return {
      listData: [],
    };
  },
  created() {
    this.getData(59, this.no, 10);
  },
  methods: {
    getData(id, pageNo, pageSize) {
      this.$request("get", "/recommend/playlist", {
        id,
        pageNo,
        pageSize,
      }).then((res) => {
        console.log(res);
        if (res.result == 100) {
          this.listData = res.data.list;
        }
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        );
        // this.betterScrollHorizontal(this.listData.length, 10); //调用一个横向滚动方法
      });
    },
    selectItem(item) {
      const id = item.tid; //获取歌单idid
      console.log("歌单id:" + id); //控制台输出歌单id
      this.$router.push({
        name: "classelist",
        params: {
          id: id, //id
        },
      });
    },
  },
};
</script>
<style scoped>
.cover > span {
  position: absolute;
  right: 0;
  bottom: 0.25rem;
  background-color: rgba(0, 0, 0, 0.326);
  border-radius: 0.5rem;
  color: white;
  font-size: 14px;
  width: 5rem;
  display: inline-block;
}
.cover {
  position: relative;
}
.wrapper {
  width: 100%;
  overflow: hidden; /*容器的宽度就是屏幕的宽度 */
}
/* ul.content { */
/* content内容区的宽度要大于wrapper容器的宽度，12个列表项 */
/* width: calc(12 * 10rem); */
/* } */
ul.content li {
  /* li默认是块级元素，修改为行内元素，但是要具备块级元素的特征 */
  display: inline-block;
  width: 10rem;
  vertical-align: top; /* 垂直方向的位置 */
}
ul.content li * {
  margin: 0.1rem;
}
ul.content li > span {
  font-size: 0.8rem;
  color: #54493b;
}
</style>
